<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<title>Cookie的写入</title>
<link href="CSS/sheet.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function submit2(){
	if(document.form1.username.value.length==0){
		alert("用户名不可为空");
		return false;
	}
	if(document.form1.password1.value.length==0){
		alert("密码不可为空");
		return false;
	}
	if(document.form1.password1.value!=document.form1.password2.value){
		alert("两次密码输入不相同");
		return false;
	}
	if(!checkemail(document.form1.mail.value)){
		alert("您输入Email地址不正确!");form1.mail.select();return false;
	}
	alert("提交成功");
	writeCookie();
	return true;
}

function testRadio(){
	var charactergroup=document.forms[0].elements["sex"];
	for(var i=0;i<charactergroup.length;i++){
		if(charactergroup[i].checked==true){
			document.cookie=encodeURI("sex="+charactergroup[i].value);
		}
	}
}
	


function writeCookie(){
	document.cookie=encodeURI("username="+document.form1.username.value);
	document.cookie=encodeURI("password="+document.form1.password1.value);
	testRadio();
}


function checkemail(str){
	 //在JavaScript中，正则表达式只能使用"/"开头和结束，不能使用双引号
	var Expression=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; 
	var objExp=new RegExp(Expression);
	if(objExp.test(str)==true){
		return true;
	}else{
		return false;
	}
}
</script>
</head>

<body>
<table width="800" height="689" border="0" align="center">
<form action="" method="post" name="form1">
  <tr>
    <td background="博客用户注册.jpg">
	  <table width="800" height="451" border="0">
        <tr>
          <td width="113" rowspan="3">&nbsp;</td>
          <td width="491" height="140">&nbsp;</td>
          <td width="182" rowspan="3">&nbsp;</td>
        </tr>
        <tr>
          <td height="175" valign="top"><table width="100%"  border="0">
              <tr>
                <td width="30%" class="zi"><div align="right">用户名：</div></td>
                <td width="70%" align="center">
                  <div align="left">
                    <input name="username" type="text" size="40" maxlength="10">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">密码：</div></td>
                <td>
                  <div align="left">
                    <input name="password1" type="password" style="font-family: Wingdings" size="20" maxlength="10" oncopy="return false" oncut="return false" onpaste="return false">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">重复密码：</div></td>
                <td>
                  <div align="left">
                    <input name="password2" type="password" style="font-family: Wingdings" size="20" maxlength="10" oncopy="return false" oncut="return false" onpaste="return false">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">姓名：</div></td>
                <td>
                  <div align="left">
                    <input name="realname" type="text" size="40" maxlength="10">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">性别：</div></td>
                <td>
                  <div align="left">
                    <input type="radio" name="sex" value="男" checked> 
                    <span class="zi">男</span>                    
                    <input type="radio" name="sex" value="女">
                    <span class="zi">                    女</span>           
                      </div></td></tr>
              <tr>
                <td class="zi"><div align="right">QQ号码：</div></td>
                <td>
                  <div align="left">
                    <input name="qqnum" type="text" size="40" maxlength="10">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">主页：</div></td>
                <td>
                  <div align="left">
                    <input name="zy" type="text" size="40" maxlength="30">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">兴趣：</div></td>
                <td>
                  <div align="left">
                    <input name="xq" type="text" size="40" maxlength="10">
                  </div></td></tr>
              <tr>
                <td class="zi"><div align="right">Email：</div></td>
                <td>
                  <div align="left">
                    <input name="mail" type="text" size="40" maxlength="30">
                  </div></td></tr>
          </table></td>
        </tr>
        <tr>
          <td valign="top"><table width="100%"  border="0">
            <tr>
              <td width="33%">&nbsp;</td>
              <td width="14%"><input type="image" src="1.gif" width="51" height="20" onClick="return submit2();"></td>
              <td width="14%"><input type="image" src="2.gif" width="51" height="20" onClick="javascript:reset();"></td>
              <td width="22%"><input type="image" src="3.gif" width="51" height="20" onClick="javascript:window.close();"></td>
              <td width="17%">&nbsp;</td>
            </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
  </form>
</table>
</body>
</html>
